package org.nlp2rdf.navigator.benchmark;

import org.aksw.commons.util.collections.StringTransformer;
import org.aksw.commons.util.collections.TransformCollection;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by Claus Stadler
 * Date: Oct 9, 2010
 * Time: 6:05:53 PM
 */
public class MyCollectionUtils
{
    /**
     * Creates a set based on the given collection.
     * If the collection already is a set, it is returned casted as a set,
     * otherwise, a new set is created and returned.
     *
     * TODO This method is probably part of some (quasi-)standard library
     *
     * @param c
     * @param <T>
     * @return
     */
    public static <T> Set<T> toSet(Collection<T> c) {
        return (c instanceof Set)
            ? (Set<T>)c
            : new HashSet<T>(c);
    }

    public static <T> Collection<String> stringView(Collection<T> col)
    {
        return TransformCollection.transformedView(col, new StringTransformer<T>());
    }
}

